#include <stdio.h>
#include <limits.h>

// 11 = 11 * 1
// 1001 = 11 * 91
// 1111 = 11 * 101
int palindrome_number_counts(int number) {
    if (number % 11 != 0) {
        return 0;
    } else {
        int value = number / 11;
        int big_max = value / 101;
        int min = INT_MAX;
        for (int big = 0; big <= big_max; big++) {
            int small_max = (value - 101 * big) / 91;
            for (int small = 0; small <= small_max; small++) {
                int all = value - big * 100 - small * 90;
                if (all < min) {
                    min = all;
                }
            }
        }
        return min;
    }
}

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int n;
        scanf("%d", &n);
        printf("%d\n", palindrome_number_counts(n));
    }
    return 0;
}
